<template>
  <div class='search'>
    <f-drawer ref='consumptionDrawer' :title='title' width='50%' @submit='handleSubmit' @visibleChange='visibleChange'>
      <bond-form ref='form1' v-if="drawerVisible&&current=='form1'"></bond-form>
    </f-drawer>
  </div>
</template>
<script>
import bondForm from "./bond_form.vue"

export default {
  name: "BondDrawer",
  props: {},
  data() {
    return {
      refs: this.$refs,
      drawerVisible: false,
      isEdit: false,
      title: "",
      current: "form1",
      formData: {},
      forms: [
        "form1"
      ]
    }
  },
  methods: {
    showDrawer(data, formName) {
      this.isEdit = false
      if (data && data.paymentId) {
        this.isEdit = true
        this.formData = data
      } else {
        this.formData = {}
      }
      this.refs["consumptionDrawer"].show()
      this.tabClick(formName)
    },
    handleSubmit(callback) {
      this.refs[this.current].handleSubmit(callback => {
        if (callback) {
          this.$emit("success")
        }
        this.refs["consumptionDrawer"].close()
      })
    },
    visibleChange(drawerVisible) {
      this.drawerVisible = drawerVisible
    },
    tabClick(name) {
      this.current = name
      if (this.current === "form1") {
        this.title = this.isEdit ? "修改资保金收款" : "资保金收款"
      }
      this.$nextTick(() => {
        this.refs[this.current].setData(this.formData)
      })
    }
  },
  computed: {
    drawerTitle: function() {
      return this.title
    }
  },
  created() {
  },
  components: { bondForm }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
